<?
include("/var/www/html/new/com.inc.php");
include("../class/ProductInfo.php");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$unLogin = false;
if(!$_SESSION['memberID']) $unLogin = true;
$pid=abs($_REQUEST['pid']);
$date=$_REQUEST['date'];
if(!$pid) exit(-1);
$did=$_SESSION['memberID'];
$str="select contact_id from uu_products where id=$pid";
$GLOBALS['le']->query($str);
$GLOBALS['le']->fetch_assoc();
$lid=$GLOBALS['le']->f("contact_id");
$str="select id,apply_did from uu_products where contact_id=".$lid." and p_status<>6 and p_status<>1";
$GLOBALS['le']->query($str);
$pids=array();
while($row=$GLOBALS['le']->fetch_assoc()){
	$pids[]=$row['id'];
    $said  = $row['apply_did'];
}
$json=array();
//TODO::获取差价
$aid = intval($_GET['aid']);
//$sql = "SELECT apply_did FROM uu_products WHERE id=$pid LIMIT 1";
//$GLOBALS['le']->query($sql);
//$GLOBALS['le']->fetch_assoc();
//$said = $GLOBALS['le']->f('apply_did');
if ($said==$aid) {
    $aid = 0;
}

if ($unLogin) {
    foreach($pids as $id){
        $pro=new ProductInfo($s, $id, $aid);
        $uprice  = $pro->uPrice_n($date);
        if($_SESSION['dtype']==5){
            $jsprice=$uprice;
        }
        $storage=$pro->dayStorage($date);
        $json[$id]=array(
            "jsprice"=>$uprice ,
            "uprice" =>$uprice,
            "storage"=>$storage
        );
    }
    
}else {
    foreach($pids as $id){
        $pro=new ProductInfo($s, $id, $aid);
        // $jsprice = $pro->jsPrice($did,$date,null);
        $jsprice = $pro->jsPrice_n($date);
        // $uprice  = $pro->uPrice($did,$date);
        $uprice  = $pro->uPrice_n($date);
        if($_SESSION['dtype']==5){
            $jsprice=$uprice;
        }
        $storage=$pro->dayStorage($date);
        $json[$id]=array(
            "jsprice"=>$jsprice ,
            "uprice" =>$uprice,
            "storage"=>$storage
        );
    }
}
echo json_encode($json);
?>